<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>智慧社区后台</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap-switch/css/bootstrap-switch.min.css">
</head>
<style>
fieldset {
	padding: .35em .625em .75em;
	margin: 0 10px;
	border: 1px solid silver;
	border-radius: 8px
}

legend {
	padding: .5em;
	border: 0;
	width: auto;
	margin-bottom: 10px
}
</style>
<body id="body" style="padding-bottom: 90px; background-color: #ECF0F5;">
	<section class="content" style="margin: 15px; background-color: white;">
		<div class="row col-md-12">
			<div class="col-md-4">
				<fieldset>
					<legend>车位出租费</legend>
					<div class="input-group">
						<span class="input-group-addon">金额：</span> <input type="text" class="form-control" id="cwczf" oninput="this.value=this.value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')"> <span class="input-group-addon">元/月</span>
					</div>
					<br />
					<button class="btn btn-primary pull-right" onclick="insert('cwczf')">保存</button>
				</fieldset>
			</div>
			<div class="col-md-4">
				<fieldset>
					<legend>住房物业费</legend>
					<div class="input-group">
						<span class="input-group-addon">金额：</span> <input type="text" class="form-control" id="zfwyf" oninput="this.value=this.value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')"> <span class="input-group-addon">元/平方米·月</span>
					</div>
					<br />
					<button class="btn btn-primary pull-right" onclick="insert('zfwyf')">保存</button>
				</fieldset>
			</div>
			<div class="col-md-4">
				<fieldset>
					<legend>商业物业费</legend>
					<div class="input-group">
						<span class="input-group-addon">金额：</span> <input type="text" class="form-control" id="sywyf" oninput="this.value=this.value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')"> <span class="input-group-addon">元/平方米·月</span>
					</div>
					<br />
					<button class="btn btn-primary pull-right" onclick="insert('sywyf')">保存</button>
				</fieldset>
			</div>
		</div>
</body>
<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<!-- layer -->
<script src="${pageContext.request.contextPath}/plugins/layer/2.4/layer.js"></script>
<script src="${pageContext.request.contextPath}/js/date.js"></script>
<script>
	var lock = false;
	$(function() {
		$
				.ajax({
					url : "${pageContext.request.contextPath}/selectPropertyPaymentByCode",
					type : "post",
					data : {
						code : 'cwczf'
					},
					dataType : "json",
					success : function(map) {
						var payment = map['payment'];
						if (payment != null) {
							$("#cwczf").val(payment.price);
						}
					}
				});
		$
				.ajax({
					url : "${pageContext.request.contextPath}/selectPropertyPaymentByCode",
					type : "post",
					data : {
						code : 'sywyf'
					},
					dataType : "json",
					success : function(map) {
						var payment = map['payment'];
						if (payment != null) {
							$("#sywyf").val(payment.price);
						}
					}
				});
		$
				.ajax({
					url : "${pageContext.request.contextPath}/selectPropertyPaymentByCode",
					type : "post",
					data : {
						code : 'zfwyf'
					},
					dataType : "json",
					success : function(map) {
						var payment = map['payment'];
						if (payment != null) {
							$("#zfwyf").val(payment.price);
						}
					}
				});
	});

	//添加或修改
	function insertPropertyPayment(code, name, unit) {
		lock = true;
		var price = $("#" + code).val();
		if (price == '') {
			layer.alert("请填写金额！");
			lock = false;
			return;
		}
		$.ajax({
			url : '${pageContext.request.contextPath}/insertPropertyPayment',
			type : "post",
			data : {
				name : name,
				code : code,
				price : price,
				unit : unit
			},
			dataType : "json",
			success : function(data) {
				var result = data['result'];
				if (result == 1) {
					layer.msg('操作成功!', {
						icon : 1,
						time : 800
					});
					lock = false;
				} else {
					layer.msg('操作失败!', {
						icon : 2,
						time : 800
					});
					lock = false;
				}
			}
		});
	}

	function insert(code) {
		if (!lock) {
			var name = "";
			var unit = "";
			if (code == 'cwczf') {
				name = "车位出租费";
				unit = "1";
			}
			if (code == 'zfwyf') {
				name = "住房物业费";
				unit = "1";
			}
			if (code == 'sywyf') {
				name = "商业物业费";
				unit = "1";
			}
			insertPropertyPayment(code, name, unit);
		}
	}
</script>
</html>
